﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class ConsoleMainMenu : ConsoleComponent
{
    List<ConsoleComponent> componentsList;

    private ConsoleComponent currentComponent;

    public ConsoleMainMenu()
    {
        componentsList = new List<ConsoleComponent>();
    }

    public void AddConsoleComponent(ConsoleComponent component)
    {
        componentsList.Add(component);
    }

    public T GetConsoleComponent<T>() where T : ConsoleComponent
    {
        foreach (ConsoleComponent c in componentsList)
            if (c is T) return c as T;

        return null;
    }

    public override void OnDrawing()
    {
        for(int i = 0;i < componentsList.Count;i ++)
        {
            // Layout main menu buttons Vertically
            if (GUI.Button(GUIHelper.RatioRect(DebugConsole.R_SPACING,
                DebugConsole.BTN_R_HEIGHT + 2 * DebugConsole.R_SPACING + i * (DebugConsole.BTN_R_HEIGHT + DebugConsole.R_SPACING),
                DebugConsole.BTN_R_WIDTH, DebugConsole.BTN_R_HEIGHT), componentsList[i].Name))
            {
                // Select or toggle current component
                if (currentComponent == componentsList[i])
                    currentComponent = null;
                else
                    currentComponent = componentsList[i];
            }
        }

        if (currentComponent != null)
            currentComponent.OnDrawing();
    }
}
